package org.lds.scheduled.job.worker.scheduler.config;

import org.lds.scheduled.job.common.exception.BusinessException;
import org.lds.scheduled.job.worker.common.enums.WorkerErrorEnum;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SchedulerConfig {

    /**
     * 创建并启动scheduler
     */
    @Bean
    public Scheduler scheduler() {
        try {
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            return scheduler;
        } catch (Exception e) {
            throw new BusinessException(WorkerErrorEnum.SCHEDULER_START_FAIL);
        }
    }

}
